#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 向队列中写入数据
import multiprocessing
import time


def work_1(q):
    try:
        n = 1
        while n < 20:
            print("work_1,%d" % n)
            q.put(n)
            time.sleep(1)
            n += 1
    except BaseException:
        print("work_1 error")
    finally:
        print("work_1 end!!!")


# 取出队列中的数据        
def work_2(q):
    try:
        n = 1
        while n < 20:
            print("word_2,%d" % q.get())
            time.sleep(1)
            n += 1
    except BaseException:
        print("work_2 error")
    finally:
        print("work_2 end")


if __name__ == "__main__":
    q = multiprocessing.Queue()
    p1 = multiprocessing.Process(target=work_1, args=(q,))
    p2 = multiprocessing.Process(target=work_2, args=(q,))
    p1.start()
    p2.start()
    p1.join()
    p2.join()
    print("all over")
